package com.mediacloud.app.newsmodule.widget;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.utils.ComponentClickUtils;

import org.json.JSONObject;

import java.util.List;

/**
 * Description:
 * <p/>
 * Created by rowandjj(chuyi)<br/>
 * Date: 16/1/7<br/>
 * Time: 下午2:05<br/>
 */
public class SampleAdapter extends BaseBannerAdapter<Model> {

    private List<Model> mDatas;

    public SampleAdapter(List<Model> datas) {
        super(datas);
    }
    public SampleAdapter() {
        super();
    }

    @Override
    public View getView(VerticalBannerView parent) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item,null);
    }

    @Override
    public void setItem(final View view, final Model data) {
        TextView tv = (TextView) view.findViewById(R.id.tv_01);
        TextView tv2 = (TextView) view.findViewById(R.id.tv_02);
        tv.setText(data.title1);
        if (data.title2 != null){
            tv2.setVisibility(View.VISIBLE);
            tv2.setText(data.title2);
            tv2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ComponentClickUtils.OpenItemComponent(tv.getContext(), data.componentItem2, (JSONObject)data.item2.extendField);
                }
            });
        }else{
            tv2.setVisibility(View.GONE);
        }

        //你可以增加点击事件
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ComponentClickUtils.OpenItemComponent(tv.getContext(), data.componentItem, (JSONObject)data.item.extendField);
            }
        });


    }
}












